// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class FACILITY_SUR_P09 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("3 FAC",3)]
  	    [HL7Field(HL7Version.v23, 3, HL7Repeat.False, HL7Required.True,"FAC")]
	    public FAC FAC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("4 PRODUCT",4)]
  	    [HL7Field(HL7Version.v23, 4, HL7Repeat.True, HL7Required.True,"PRODUCT_SUR_P09")]
	    public PRODUCT_SUR_P09[] PRODUCT {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("8 PSH",8)]
  	    [HL7Field(HL7Version.v23, 8, HL7Repeat.False, HL7Required.True,"PSH")]
	    public PSH PSH {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("9 FACILITY_DETAIL",9)]
  	    [HL7Field(HL7Version.v23, 9, HL7Repeat.True, HL7Required.True,"FACILITY_DETAIL_SUR_P09")]
	    public FACILITY_DETAIL_SUR_P09[] FACILITY_DETAIL {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			FAC = PopSegmentParseAndCheckRequired<FAC>(availableData, options, "FAC");
			PRODUCT = ProcessGroupArray<PRODUCT_SUR_P09>(availableData, options, "PRODUCT");
			PSH = PopSegmentParseAndCheckRequired<PSH>(availableData, options, "PSH");
			FACILITY_DETAIL = ProcessGroupArray<FACILITY_DETAIL_SUR_P09>(availableData, options, "FACILITY_DETAIL");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isFAC = availableData.StartsWith("FAC", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("FAC", options.Version) || isFAC) {
				return isFAC;
			}
			PRODUCT_SUR_P09 testPRODUCT_SUR_P09 = new PRODUCT_SUR_P09();
			bool grpCCPRODUCT_SUR_P09 = (testPRODUCT_SUR_P09.CanConsume(availableData, options));
			if (IsRequired("PRODUCT", options.Version) || grpCCPRODUCT_SUR_P09) {
				return grpCCPRODUCT_SUR_P09;
			}
			bool isPSH = availableData.StartsWith("PSH", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PSH", options.Version) || isPSH) {
				return isPSH;
			}
			FACILITY_DETAIL_SUR_P09 testFACILITY_DETAIL_SUR_P09 = new FACILITY_DETAIL_SUR_P09();
			bool grpCCFACILITY_DETAIL_SUR_P09 = (testFACILITY_DETAIL_SUR_P09.CanConsume(availableData, options));
			if (IsRequired("FACILITY_DETAIL", options.Version) || grpCCFACILITY_DETAIL_SUR_P09) {
				return grpCCFACILITY_DETAIL_SUR_P09;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "FACILITY";
			}
        }

        static FACILITY_SUR_P09() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(FACILITY_SUR_P09));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (FAC != null) {
			string segmentValue = FAC.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (PRODUCT != null && PRODUCT.Length > 0) {
			for (int i = 0; i < PRODUCT.Length; i++) {
				string segmentValue = PRODUCT[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (PSH != null) {
			string segmentValue = PSH.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (FACILITY_DETAIL != null && FACILITY_DETAIL.Length > 0) {
			for (int i = 0; i < FACILITY_DETAIL.Length; i++) {
				string segmentValue = FACILITY_DETAIL[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

